package com.ruoyi.web.controller.client;


import com.ruoyi.client.domain.SysClient;
import com.ruoyi.client.domain.SysLinkman;
import com.ruoyi.client.service.ISysClientService;
import com.ruoyi.client.service.ISysLinkmanService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("/client/messages")
public class ClientController extends BaseController {
    @Autowired
    private ISysClientService iSysClientService;
    @Autowired
    ISysLinkmanService iSysLinkmanService;
    /**
     * 获取客户列表
     * @param sysClient
     * @return
     */
    @PreAuthorize("@ss.hasPermi('client:messages:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysClient sysClient) {
        startPage();
        List<SysClient> list=iSysClientService.selectClientList(sysClient);
        return getDataTable(list);
    }

    /**
     * 根据客户id获取客户联系人
     * @return
     */
    @PreAuthorize("@ss.hasPermi('client:messages:getlinkmanById')")
    @PostMapping("getlinkmanById")
    public AjaxResult getlinkmanById(Integer clientId){
        System.err.println("客户id为："+clientId);
        //根据客户id去查询联系人表
        List<SysLinkman> list=iSysLinkmanService.getlinkmanById(clientId);
        System.err.println("联系人列表为："+list);
        return success(list);
    }

    @PreAuthorize("@ss.hasPermi('client:messages:submitClientForm')")
    @PostMapping("submitClientForm")
    public AjaxResult submitClientForm(SysClient sysClient){
        System.err.println("前端传过来提交的客户信息为："+sysClient);
        iSysClientService.saveClient(sysClient);
        return success();
    }




}
